﻿using AutoMapper;
using FC.ERP.TMom.Api.AppHandlers.Commands.EssentialDatas.FactoryManages.Lines;
using FC.ERP.TMom.Domain;
using FC.ERP.TMom.ErrorCode;
using FC.ERP.TMom.Infrastructure.Interfaces;
using MediatR;

namespace FC.ERP.TMom.Api.AppHandlers.CommandHandlers.EssentialDatas.FactoryManages.Lines
{
    public class LineAddCommandHandler : IRequestHandler<LineAddCommand, APIResult<int>>
    {
        private readonly IBaseRepository<Line> linerepository;
        private readonly IMapper mapper;
        public LineAddCommandHandler(IBaseRepository<Line> linerepository, IMapper mapper)
        {
            this.linerepository = linerepository;
            this.mapper = mapper;
        }

        public async Task<APIResult<int>> Handle(LineAddCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.Code=ResultCode.添加成功;
            result.Message=ResultCode.添加成功.ToString();
            var entity=mapper.Map<Line>(request);
            await linerepository.Add(entity);
            return await Task.FromResult(result);
        }
    }
}
